package com.ncmmall.application.jobs;

import com.ncmmall.application.business.marketing.ShoppingCardApplication;
import com.ncmmall.application.business.marketing.ShoppingCardOrderApplication;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.springframework.scheduling.quartz.QuartzJobBean;

/**
 * 自动取消购物订单
 * 自动下架过期购物卡
 *
 * @author likaikai
 * @date 2020-3-13 10:27:44
 */
@Slf4j
public class AutoDisableShoppingCardJobSchedulingApplication extends QuartzJobBean {

    private final ShoppingCardApplication shoppingCardApplication;
    private final ShoppingCardOrderApplication shoppingCardOrderApplication;

    public AutoDisableShoppingCardJobSchedulingApplication(ShoppingCardApplication shoppingCardApplication, ShoppingCardOrderApplication shoppingCardOrderApplication) {
        this.shoppingCardApplication = shoppingCardApplication;
        this.shoppingCardOrderApplication = shoppingCardOrderApplication;
    }

    public void execute() {
        try {
            log.info("购物卡定时任务开始");
            shoppingCardApplication.autoDisable();
            shoppingCardOrderApplication.autoCancelOrders();
            log.info("购物卡定时任务结束");
        } catch (Exception e) {
            log.error("[购物卡定时任务异常]", e);
        }
    }

    @Override
    protected void executeInternal(JobExecutionContext context) {

    }
}
